Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skew functionality to pygame.transform #2143

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

Temmie3754
Copy link
Member

This adds a skew function to the transform module as requested by #2098 with modifications to support inputs of any 4 coordinates to map the surface to. Do note this is still a WIP so the full implementation for release has not been completed, feel free however to test out the current algorithm implementation and submit feedback on it.

@Temmie3754 Temmie3754 changed the title Adds skew functionality to pygame.transform Add skew functionality to pygame.transform May 4, 2023
@Temmie3754 Temmie3754 marked this pull request as ready for review May 9, 2023 10:54
@Temmie3754 Temmie3754 requested a review from a team as a code owner May 9, 2023 10:54
@gresm
Copy link
Contributor

gresm commented May 9, 2023

Just two comments regarding this pull request:

  1. The cython files: scrolling through the diff, it seems that the changes are caused by regeneration of these files with a newer version of cython (0.29.30 -> 0.29.34). I assume that it was accidental, but if it were intentional, this should be done in a different pull request.
  2. In pygame.transform.skew #2098 there is discussion regarding how this function should be named, what's the final decision?

@Temmie3754
Copy link
Member Author

  1. Fixed that.
  2. I think using skew() would be most appropriate for this implementation since it doesn't perform a perspective warp operation or a transformation but rather attempts to map all horizontal lines in the original surface to new positions in the new surface by changing the angle and length of each line in the surface. I believe that a quad_transform() naming scheme would be more appropriate for a different implementation that mapped points using a transformation matrix. skew() also fits the naming scheme of the transform module better since quads are not mentioned outside of _sdl2 so using it here may bring about more confusion, especially since this does not work with the quads drawn by the _sdl2 module.

@zoldalma999 zoldalma999 added New API This pull request may need extra debate as it adds a new class or function to pygame transform pygame.transform labels May 20, 2023
@simplyrohan
Copy link
Contributor

it doesn't perform a perspective warp operation or a transformation but rather attempts to map all horizontal lines in the original surface to new positions in the new surface by changing the angle and length of each line in the surface.

I do see use cases for this, but it may be redundant. Another thread involves mapping a surface to new points. This skew functionality could be achieved using that method. Although that thread hasn't seen much activity...

@MyreMylar
Copy link
Member

I like the name skew, it is familiar to me for this type of operation (and is the sort of word I'd look for in a transform submodule to get this effect). Photoshop and GIMP use shear for this operation, so that is another option if others would prefer that.

I'm happy having a function like this even if you could achieve the same thing with a more complicated warping function as it is likely that users would look for something like this and might not grasp that a more complicated function could be used for the same thing.

If needed we could eventually reduce underlying code duplication by making this API call the more complicated spatial transform with some fixed parameters.

@MyreMylar MyreMylar added this to the 2.4.0 milestone Aug 14, 2023
@Starbuck5 Starbuck5 modified the milestones: 2.4.0, 2.5.0 Dec 25, 2023
@Starbuck5 Starbuck5 removed this from the 2.5.0 milestone May 30, 2024
@MyreMylar MyreMylar requested a review from a team as a code owner October 5, 2024 15:58
Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried this out finally. Unfortunately, there is no test or usage example and when I tired to use it like so:

import pygame


display_surf = pygame.display.set_mode((1280, 600))
display_surf.fill((255, 255, 255))

walt = pygame.image.load("images/walt.png").convert_alpha()

walt_2 = pygame.transform.skew(walt, [[0, 0], [417, 0], [0, 364], [417, 364]])
walt_3 = pygame.transform.skew(walt, [[0, 0], [417, 0], [0, 364], [417, 364]])

pygame.init()

clock = pygame.time.Clock()

running = True

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    display_surf.fill((255, 255, 255))
    display_surf.blit(walt, (0, 100))
    display_surf.blit(walt_2, (417, 100))
    display_surf.blit(walt_3, (834, 100))

    pygame.display.flip()

    clock.tick(60)

I get a segmentation fault.

I may be doing it wrong, but in any case we defintely need some clearer documentation on the four points and the order they are supplied in. I'm assuming it goes - [top_left, top_right, bottom_left, bottom_right] but I could be wrong. I'm also assuming the supplied points are in pixels.

Anyway, I think this could be cool if it worked.

Copy link
Contributor

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reason to believe you are going to push some commits soon, this is just rather minor things I noticed I thought were worth mentioning.

docs/reST/ref/transform.rst Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
src_c/transform.c Outdated Show resolved Hide resolved
@Temmie3754
Copy link
Member Author

Will probably need to write some tests for this and maybe some further changes to the docs but otherwise at this point I think it is fully functional, unless anyone else has other ideas for this PR.

Copy link
Contributor

@damusss damusss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I can make a PR that fixes the same thing for threshold. Now you don't need to worry about the original _color_from_obj function.

src_c/transform.c Outdated Show resolved Hide resolved
}
}
else {
if (!pg_MappedColorFromObj(colorobj, surf->format, &bgcolor,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A PR has been merged that requires the surface itself (not the format). Since you are not using _color_from_obj anymore, you should move it back from where you moved it, which should fix the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New API This pull request may need extra debate as it adds a new class or function to pygame transform pygame.transform
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants